/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package toolz;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.imageio.ImageIO;

import GUI.ChartTools.WBRG_PaintScale;

/**
 *
 * @author bunkowski
 */
public class WriteHetamapScaleToFile {

    public BufferedImage getLegendImage(int xSize, int ySize) {
        WBRG_PaintScale paintScale = new WBRG_PaintScale(0, 1);

        BufferedImage bi = new BufferedImage(xSize, ySize, BufferedImage.TYPE_INT_RGB);
        for (int x = 0; x < xSize; x++) {
            for (int y = 0; y < ySize; y++) {
                int color;
                if (xSize > ySize) {
                    color = ((Color) paintScale.getPaint((double)x / (double)xSize)).getRGB();
                } else {
                    color = ((Color) paintScale.getPaint((double)y / (double)ySize)).getRGB();
                }
                bi.setRGB(x, y, color);
            }
        }
        return bi;
    }

    public static void main(String[] args) {
        try {
            WriteHetamapScaleToFile x = new WriteHetamapScaleToFile();
            BufferedImage i = x.getLegendImage(400, 100);
            ImageIO.write(i, "png", new File("paintscale.png"));
        } catch (IOException ex) {
            Logger.getLogger(WriteHetamapScaleToFile.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}
